Repository navigation
Honor custom item serializers in typed NumPy arrays - #296
Closed
pengpengyi92 wants to merge 1 commit into
Closed
pengpengyi92 wants to merge 1 commit into
pengpengyi92 wants to merge 1 commit into
Conversation
Signed-off-by: Pengyi Peng <pengpengyi92@users.noreply.github.com>
pengpengyi92
requested review from
feussy,
hintse,
ptomecek and
timkpaine
as code owners
November 13, 2026 18:52
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #296 +/- ##
==========================================
+ Coverage 93.85% 93.86% +0.01%
==========================================
Files 205 205
Lines 22944 23043 +99
Branches 1511 1517 +6
==========================================
+ Hits 21533 21629 +96
- Misses 1120 1122 +2
- Partials 291 292 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
2 of 11 tasks
4 of 11 tasks
Member
|
Thanks for the PR, i've consolidated several open ones in #299 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Honor the declared custom item serializer when serializing typed
NDArrayobject arrays. Addresses #58, reported by @NeejWeej.
The current
.tolist()->any_schemapath loses the item's declaredPydantic serialization schema. This can raise
PydanticSerializationErrorfor custom objects, or serialize
ccflow.Enumas values rather than names.This change uses a rank-specific, cached
TypeAdapterfor arrays whoseitems actually retain their declared custom-schema type. It forwards
serialization mode, filters, aliases and context. Untyped arrays and native
NumPy dtypes keep the existing path. NumPy-coerced enum values also keep the
existing path: numbers must not be sent to a serializer expecting objects.
Validation and NumPy dtype conversion are intentionally unchanged.
Regression tests cover 1D/2D/3D and empty object arrays, Python vs JSON mode,
index filters, optional fields, model aliases/filters, context, enum names,
untyped objects and the coerced-IntEnum boundary. No dependency/version
changes; the original MIT notices in these two files are preserved.
Type of Change
Local validation
Windows 11, Python 3.12.14. Base:
83f2b0ac7128c08c92f2b6fd60f58723ac47635a.These are scoped local results, not a claim of complete CI or coverage.
accounts for 21 passing cases. The context/enum selection has an existing
environment-dependent skip. Ruff check and format check pass (208 files).
yield 8 failed, 13 passed. The base's original 7 NDArray tests pass.
fails on the base and passes with this change. Candidate NDArray tests plus
that separate example: 22 passed. CSP 0.19.1: 22 passed, preserving
integer output for values already coerced by NumPy.
test_union_fieldfails onboth the clean base and candidate. Candidate: 19 passed, 1 failed,
1 skipped (context API unavailable); base: 6 passed, 1 failed. This PR
does not attempt an unrelated union-validation change.
The native CSP check uses the issue's class-based Enum example with
TypeAdapter(NDArray[Side]). Expected output is enum names on CSP 0.18,and the unchanged numeric output after NumPy coercion on CSP 0.19.
Not run: full
make test, cross-platform CI, optional-service suites orperformance benchmarks. Adapter caching is not a measured speedup claim.
Checklist
make lint(Ruff commands above pass; other tools not run)make test(scoped results and inherited lower-version failure above)Prepared with OpenAI Codex assistance. Local tests and clean-base controls
were actually executed. DCO sign-off was explicitly authorized by the author
for this contribution only.
Upstream CI readback - 2026-11-14 (Asia/Shanghai)
For head
1f1afbc6ba87707fc915d2e1e4913aa7e84c4110, all 16 Linux/macOSbuild-matrix jobs in run 43486775195
succeeded, together with DCO and both Codecov checks (19 successful checks
observed). This is separate from the scoped Windows runs above and does not
claim maintainer approval or merge.